package com.szmmsoft.mp.controller;

import com.szmmsoft.mp.common.anno.Log;
import com.szmmsoft.mp.common.anno.Sign;
import com.szmmsoft.mp.common.exception.BusinessCode;
import com.szmmsoft.mp.common.exception.BusinessException;
import com.szmmsoft.mp.common.model.R;
import com.szmmsoft.mp.common.until.validator.ValidationUtils;
import com.szmmsoft.mp.model.dto.LoginDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Description of the class.
 *
 * @author ethan
 * @version 1.0.0
 * @since 2024-10-14
 */
@RequestMapping("api/test/v1")
@RestController
@Slf4j
@Api(tags = "测试")
public class TestController {

    @GetMapping("get")
    @ApiOperation("获取")
    public R get(String id){
        ValidationUtils.throwIfEmpty(null,"ID不可为空");
        return R.ok("你好"+id);
    }
    @PostMapping("save")
    public R testPost(@RequestBody Map<String,String>test){
        return R.ok("你好"+test);
    }

    @GetMapping("getInfo/{id}")
    public R getInfo(@PathVariable("id") String id){
        log.info(BusinessCode.UNAUTHORIZED.getCode()+"");
        throw new BusinessException(BusinessCode.UNAUTHORIZED);
    }
    @GetMapping("login")
    @Sign
    public R login(@RequestBody LoginDTO loginDTO){
        return R.ok("登录成功");
    }
}
